package com.example.s10freemaker.controller;

import com.example.s10freemaker.pojo.User;
import com.example.s10freemaker.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @auther Qiang
 * @date 2022/4/6 9:33
 */

@Controller
public class UserController
{

    @Autowired
    private IUserService userService;

    @RequestMapping("userlist")
    public String userlist(Model map)
    {
        System.out.println("userlist");
        List userList = userService.list();
        map.addAttribute("userList",userList);
        return "user";
    }

    @RequestMapping("modify")
    public String modify(Long id,Model map)
    {
        User u = userService.getById(id);
        map.addAttribute("user",u);
        return "modify";
    }

    @RequestMapping("modifychk")
    public String modifychk(User user)
    {
        System.out.println("user:"+user);
        userService.updateById(user);
        return "redirect:/userlist";
    }
}
